package com.wzdigit.wms.wms.controller.TransferWareHouse;

import com.wzdigit.framework.exception.RestStatusException;
import com.wzdigit.framework.model.response.ErrorEntity;
import com.wzdigit.wms.basic.util.HttpSessionUtil;
import com.wzdigit.wms.basic.client.response.Result;
import com.wzdigit.wms.basic.client.response.transfer.GdnRemoveCtnrResponse;
import com.wzdigit.wms.basic.client.response.transfer.GdnRemoveSACResponse;
import com.wzdigit.wms.wms.constant.WmsWareConstant;
import com.wzdigit.wms.wms.service.transfer.GdnRemoveCtnrService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 取消装运PDA
 * Created by zyf on 2021/5/27 15:29
 */
@RestController
@Api(tags = "取消装运PDA")
@RequestMapping(value = WmsWareConstant.API_VERSION)
public class GdnRemoveCtnrController {
    public static final String REQUEST_MODEL = "/gdnRemoveCtnr";

    @Autowired
    private GdnRemoveCtnrService gdnRemoveCtnrService;

    @ApiOperation(value = "取消装运PDA主页",notes = "取消装运PDA主页")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @GetMapping(value = REQUEST_MODEL + "/list")
    public Result<GdnRemoveCtnrResponse> removeCtnr(
            String gdnNo,
            HttpServletRequest servletRequest,
            HttpServletResponse servletResponse) {
        try {
            return gdnRemoveCtnrService.searchGdnRemoveCtnr(gdnNo);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }

    @ApiOperation(value = "整单取消",notes = "整单取消")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @GetMapping(value = REQUEST_MODEL + "/removeAll")
    public Result<GdnRemoveSACResponse> removeAll(
            String gdnNo,
            HttpServletRequest servletRequest,
            HttpServletResponse servletResponse) {
        try {
            return gdnRemoveCtnrService.removeAll(gdnNo);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }

    @ApiOperation(value = "扫描SN取消",notes = "扫描SN取消")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @GetMapping(value = REQUEST_MODEL + "/removeBySn")
    public Result<GdnRemoveSACResponse> removeOne(
            String gdnNo, String goodsSn,
            HttpServletRequest servletRequest,
            HttpServletResponse servletResponse) {
        try {
            return gdnRemoveCtnrService.removeOne(gdnNo,goodsSn);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }

    @ApiOperation(value = "取消装柜(提交)",notes = "取消装柜(提交)")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @PostMapping(value = REQUEST_MODEL + "/removeSubmit/{gdnNo}/{whsId}/{flag}")
    public Result<String> removeCtnrSubmit(
            @PathVariable("gdnNo") String gdnNo, @PathVariable("whsId") Integer toWhsId,
            @RequestBody List<String> removeSnList, @PathVariable("flag") Boolean flag,
            HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception {
        try {
            String userName = HttpSessionUtil.getLoginName(servletRequest);
            return gdnRemoveCtnrService.removeSubmit(gdnNo,toWhsId,
                    flag,userName,removeSnList,servletRequest,servletResponse);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }


}
